<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
  <title>后台管理系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="/resources/css/dpl-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/bui-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/page-min.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div class="container">
  <form id="J_Form" class="form-horizontal" action="/member/save">

    <h3>代理商信息</h3>
   <input type="hidden" name="id" id="id" value="${data.id}"/>
    <input type="hidden" name="userType" id="userType" value="${data.type}"/>
    <input type="hidden" name="isPartner" id="isPartner" value="${data.isPartner}"/>
    <div class="row">
      <div class="control-group span12">
        <label class="control-label">代理商ID：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          ${data.account}
        </div>
      </div>

      <div class="control-group span12">
        <label class="control-label">真实姓名：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          ${data.cardName}
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span12">
        <label class="control-label">微信昵称：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          ${data.nickName}
        </div>
      </div>

      <div class="control-group span12">
        <label class="control-label">性别：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <c:choose>
            <c:when test="${data.sex eq '1'}">男</c:when>
            <c:when test="${data.sex eq '2'}">女</c:when>
            <c:otherwise>未知</c:otherwise>
          </c:choose>
        </div>
      </div>
    </div>


    <div class="row">
      <div class="control-group span20">
        <label class="control-label">代理地区：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <c:choose>
            <c:when test="${data.type eq 'Gold'}"> ${data.userProvinceName}/${data.userCityName}/${data.userAreaName}</c:when>
            <c:when test="${data.type eq 'General' && data.isPartner ne '1'}"> ${data.userProvinceName}/${data.userCityName}/${data.userAreaName}</c:when>
            <c:when test="${data.type eq 'General' && data.isPartner eq '1'}">
              <c:choose>
                <c:when test="${data.userLevel eq '0'}"> ${data.userProvinceName}</c:when>
                <c:when test="${data.userLevel eq '1'}"> ${data.userProvinceName}/${data.userCityName}</c:when>
                <c:when test="${data.userLevel eq '2'}"> ${data.userProvinceName}/${data.userCityName}</c:when>
                <c:otherwise> ${data.userProvinceName}/${data.userCityName}/${data.userAreaName}</c:otherwise>
              </c:choose>
            </c:when>
            <c:otherwise></c:otherwise>
          </c:choose>

        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span12">
        <label class="control-label">推荐人：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          ${data.tdyj}
        </div>
      </div>

      <div class="control-group span12">
        <label class="control-label">类型：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <c:choose>
            <c:when test="${data.type eq 'Gold'}">金牌代理</c:when>
            <c:when test="${data.type eq 'General' && data.isPartner ne '1'}">全国总代</c:when>
            <c:when test="${data.type eq 'General' && data.isPartner eq '1'}">
              <c:choose>
                <c:when test="${data.userLevel eq '0'}">省级合伙人</c:when>
                <c:when test="${data.userLevel eq '1'}">副省级合伙人</c:when>
                <c:when test="${data.userLevel eq '2'}">地市级合伙人</c:when>
                <c:otherwise>区县合伙人</c:otherwise>
              </c:choose>
            </c:when>
            <c:otherwise>普通用户</c:otherwise>
          </c:choose>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span12">
        <label class="control-label">当前状态：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <c:choose>
            <c:when test="${data.status eq 'NORMAL'}">启用</c:when>
            <c:when test="${data.status eq 'FROZEN'}">冻结</c:when>
            <c:otherwise>待审核</c:otherwise>
          </c:choose>
        </div>
      </div>

      <div class="control-group span12">
        <label class="control-label">加入时间：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          ${data.dateStr}
        </div>
      </div>
    </div>


      <h3>升级内容</h3>
    <div class="row">
      <div class="control-group span20">
        <label class="control-label">微信名称：</label>
        <div class="controls">
          <input name="nickName" type="text" data-rules="{maxlength:20}" value="${data.nickName}" class="input-normal control-text" style="width:200px;">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span20">
        <label class="control-label">真实姓名：</label>
        <div class="controls">
          <input name="cardName" type="text" data-rules="{maxlength:20}" value="${userName}" class="input-normal control-text" style="width:200px;">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span20">
        <label class="control-label">联系电话：</label>
        <div class="controls">
          <input name="mobile" type="text" data-rules="{maxlength:20}" value="${mobile}" class="input-normal control-text" style="width:200px;">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span20">
        <label class="control-label">身份证号：</label>
        <div class="controls">
          <input name="idCard" type="text" data-rules="{maxlength:20}" value="${data.idCard}" class="input-normal control-text" style="width:200px;">
        </div>
      </div>
    </div>
    <div class="row">
      <div class="control-group span20">
        <label class="control-label">银行名称：</label>
        <div class="controls">
          <input name="bankName" type="text" data-rules="{maxlength:20}" value="${data.bankName}" class="input-normal control-text" style="width:200px;">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span20">
        <label class="control-label">银行卡号：</label>
        <div class="controls">
          <input name="cardNo" type="text" data-rules="{maxlength:20}" value="${data.cardNo}" class="input-normal control-text" style="width:200px;">
        </div>
      </div>
    </div>

      <div class="row">
          <div class="control-group span20">
            <label class="control-label">升级为：</label>
            <div style="display:inline;height:40px;margin-left: 10px;">
                <select name="type" id="type" onchange="showLevel()">
                  <option value="Customer" <c:if test="${data.type eq 'Customer'}">selected</c:if>>普通用户</option>
                  <option value="Gold" <c:if test="${data.type eq 'Gold'}">selected</c:if>>金牌代理商</option>
                  <option value="General" <c:if test="${data.type eq 'General'}">selected</c:if>>全国总代</option>
                  <option value="Partner" <c:if test="${data.type eq 'Partner'}">selected</c:if>>区域合伙人</option>
                </select>
            </div>
          </div>
        </div>

        <div class="row" id="level_row" style="display: none;margin-top: 10px;">
          <div class="control-group span20">
            <label class="control-label">所负责区域级别：</label>
            <div style="display:inline;height:40px;margin-left: 10px;">
              <select name="userLevel" id="userLevel" onchange="showLabel()">
                <option value="">请选择</option>
                <option value="0" <c:if test="${data.userLevel=='0'}">selected</c:if>>省级</option>
                <option value="1" <c:if test="${data.userLevel=='1'}">selected</c:if>>副省级</option>
                <option value="2" <c:if test="${data.userLevel=='2'}">selected</c:if>>地市</option>
                <option value="3" <c:if test="${data.userLevel=='3'}">selected</c:if>>区县</option>
              </select>
            </div>
          </div>
        </div>

        <div class="row" id="area_row" style="margin-top: 10px;">
          <div class="control-group span20">
            <label class="control-label">所负责区域：</label>
            <div style="display:inline;height:40px;margin-left: 10px;">
              <select name="userProvince" id="userProvince" onchange="loadCity($(this).val())">

              </select>
              <input type="hidden" name="userProvinceName" id="userProvinceName" value="${data.userProvinceName}">
              <select name="userCity" id="userCity" onchange="loadArea()">

              </select>
              <input type="hidden" name="userCityName" id="userCityName" value="${data.userCityName}">
              <select name="userArea" id="userArea" >

              </select>
              <input type="hidden" name="userAreaName" id="userAreaName" value="${data.userAreaName}">
            </div>
          </div>

          <div class="control-group span20" style="margin-top: 5px;">
            <label class="control-label">详细地址：</label>
            <div style="display:inline;height:40px;margin-left: 10px;">
              <input name="address" type="text" data-rules="{maxlength:80}" value="${address}" class="input-normal control-text" style="width:300px;">
            </div>
          </div>

        </div>

    <div class="row" style="margin-top: 5px;">
      <div class="control-group span12">
        <label class="control-label">推荐人账号：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <input name="recommendName" id="recommendName" type="text" data-rules="{maxlength:20}" value="${data.tdyj}"
                 class="input-normal control-text">
          <input type="button" value="查询" onclick="queryUser()"/>
          <input type="hidden" id="recommendId" name="recommendId" value="${data.recommendId}"/>
        </div>
      </div>
    </div>
    <div  id="user_list" style="display: none;margin-top: 10px;">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;推荐人:
      <span id="span_list">

        </span>
    </div>

    <input type="hidden" id="hide_province" value="${province}"/>
    <input type="hidden" id="hide_city" value="${city}"/>
    <input type="hidden" id="hide_area" value="${area}"/>

    <div class="row form-actions actions-bar">
      <div class="span13 offset3 ">
        <button type="submit" class="button button-primary">保存</button>
       <button type="button" class="button" onclick="back()">返回</button>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript" src="/resources/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/resources/js/sea.js"></script>
<script type="text/javascript" src="/resources/js/bui-min.js"></script>
<script type="text/javascript" src="/resources/js/config-min.js"></script>


<script type="text/javascript">
  BUI.use('common/page'); //页面链接跳转
  BUI.use(['bui/tree','bui/form','bui/select','bui/data'],function (Tree,Form,Select,Data) {

    var form = new Form.HForm({
      srcNode : '#J_Form',
      submitType:"ajax",
      listeners:{
        beforesubmit:function(){
          var userType = $("#userType").val();
          var type = $("#type").val();
          /*if(userType!=''){
            if(userType=='General'){
              if(type=='Gold'){
                BUI.Message.Alert("您已是全国总代，无法降级！");
                return false;
              }
            }
          }
          var isPartner = $("#isPartner").val();
          if(isPartner!=''){
            if(isPartner=='1'){
                if(type=='Gold'){
                  BUI.Message.Alert("您已是区域合伙人，无法降级！");
                  return false;
              }
              if(type=='General'){
                BUI.Message.Alert("您已是区域合伙人，无法降级！");
                return false;
              }
            }
          }*/

          if(type!=undefined){
            if(type=='Partner'){//区域合伙人
               var userLevel = $("#userLevel").val();
              if(userLevel=='2'){
                var area = $("#userArea").val();
                if(area==undefined||area==''){
                  BUI.Message.Alert("请选择区县！");
                  return false;
                }
              }else if(userLevel=='1'){
                var city = $("#userCity").val();
                if(city==undefined||city==''){
                  BUI.Message.Alert("请选择地市！");
                  return false;
                }
              }
            }
            $("#userAreaName").val($("#userArea").find("option:selected").text());
            $("#userCityName").val($("#userCity").find("option:selected").text());
            $("#userProvinceName").val($("#userProvince").find("option:selected").text());
          }
          return true;
        }
      },
      callback:function(data){
        BUI.Message.Alert(data.msg,function(){
          if(data.success){
            back();
          }
        },'info');
      }
    });

    form.render();
  });

  function back(){
    var id = "user_list";
    var enter = '${enter}';
    if(enter == '1')
      id = "weixin_user";

    top.topManager.openPage({
      id : id,
      isClose : true
    });
    top.topManager.reloadPage(id);
  }

  $(function(){
    var type = '${data.type}';
    if(type=='Partner'){
      $("#level_row").show();
      $("#area_row").show();
    }
    loadProvince();
  })

  function showLevel(){
      if($("#type").val()=="Partner"){
        $("#level_row").show();
      }else{
        $("#level_row").hide();

      }
  }
  function showLabel(){
    var userLevel = $("#userLevel").val();
    if(userLevel=='0'){
      $("#userProvince").show();
      $("#userCity").hide();
      $("#userArea").hide();
    }else if(userLevel=='1'){
      $("#userProvince").show();
      $("#userCity").show();
      $("#userArea").hide();
    }else if(userLevel=='2'){
      $("#userProvince").show();
      $("#userCity").show();
      $("#userArea").hide();
    }else if(userLevel=='3'){
      $("#userProvince").show();
      $("#userCity").show();
      $("#userArea").show();
    }
  }
  function loadProvince(){
    $.ajax({
      url:"/front/loadCitys?r="+Math.random(),
      type:"post",
      data:{
        pid:"0"
      },
      success:function(res){
        if(res.success){
          fillSelect("userProvince",res.data,$("#hide_province").val());
          loadCity();
        }
      },
      error:function(){

      }
    })
  }
  function loadCity(){
    $.ajax({
      url:"/front/loadCitys?r="+Math.random(),
      type:"post",
      data:{
        pid:$("#userProvince").val()
      },
      success:function(res){
        if(res.success){
          fillSelect("userCity",res.data,$("#hide_city").val());
          loadArea();
        }
      },
      error:function(){

      }
    });
  }
  function loadArea(){
      $.ajax({
        url:"/front/loadCitys?r="+Math.random(),
        type:"post",
        data:{
          pid:$("#userCity").val()
        },
        success:function(res){
          if(res.success){
            fillSelect("userArea",res.data,$("#hide_area").val());
          }
        },
        error:function(){

        }
      });
  }
  function fillSelect(id,data,no){
    var html = "";
    $.each(data,function(i,n){
      var ckd = "";
      if(n.no == no){
        ckd = "selected";
      }
      html += "<option value='"+n.no+"' "+ckd+">"+n.name+"</option>";
    });
    $("#"+id).html(html);
  }

  function queryUser(){
    var recommendName = $("#recommendName").val();
    if(recommendName!=''){
      $("#user_list").show();
      $.ajax({
        url:"/front/listUser",
        type:"post",
        data:{
          name:recommendName
        },
        success:function(res){
          if(res.success){
            var html = "";
            $.each(res.data,function(i,n){
              var chk = "";
              html += "&nbsp;&nbsp;<input type='radio' name='user' value='"+n.id+"_"+n.account+"' id='id_"+n.id+"' " +
                      "onclick=\"selectData('"+n.id+"')\" /><img src='"+n.headimgUrl+"' style='width:80px;height:80px;'/>"+n.account;
            });
            $("#span_list").html(html);
          }
        },
        error:function(){}
      })
    }else{
      $("#user_list").hide();
    }
  }
  function selectData(id){
    var obj = $("#id_"+id);
    if(obj!=undefined){
      var val = obj.val();
      if(val!=''){
        var id = val.split("_")[0];
        var account = val.split("_")[1];
        $("#recommendId").val(id);
        $("#recommendName").val(account);
      }
    }
  }


</script>

</body>
</html> 